<template>
  <div class="tool-bar-ri">
    <span class="username">{{ departmentName }}</span>
    <div class="header-icon">
      <AssemblySize id="assemblySize" class="icon" />
      <Language id="language" class="icon" />
      <SearchMenu id="searchMenu" class="icon" />
      <ThemeSetting id="themeSetting" class="icon" />
      <Message id="message" class="icon" />
      <Fullscreen id="fullscreen" class="icon" />
    </div>
    <span class="username">{{ username }}</span>
    <Avatar />
  </div>
</template>

<script setup lang="ts">
import { computed } from "vue";
import { useUserStore } from "@/stores/modules/user";
import AssemblySize from "./components/AssemblySize.vue";
import Language from "./components/Language.vue";
import SearchMenu from "./components/SearchMenu.vue";
import ThemeSetting from "./components/ThemeSetting.vue";
import Message from "./components/Message.vue";
import Fullscreen from "./components/Fullscreen.vue";
import Avatar from "./components/Avatar.vue";

const userStore = useUserStore();
const username = computed(() => userStore.userInfo.name);
const departmentName = computed(() => userStore.userInfo.departmentName);

// computed 是 Vue.js 提供的一个响应式 API，用于计算一个数据源的派生值，并将该派生值作为一个响应式的数据源来使用。
// 在上面的代码中，computed 函数计算 userStore.userInfo.name 这个数据源的派生值，也就是根据用户信息对象 userInfo
// 计算出用户名称，而且这个计算逻辑会在 userStore.userInfo 对象发生变化时自动重新计算。这样，只要 userStore.userInfo
// 对象的属性值发生变化，就会自动触发 username 的更新，从而保证了页面的实时响应。
</script>

<style scoped lang="scss">
.tool-bar-ri {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-right: 25px;
  .header-icon {
    display: flex;
    align-items: center;
    & > * {
      margin-left: 21px;
    }
  }
  .username {
    margin: 0 20px;
    font-size: 15px;
  }
}
</style>
